<template>
  <!-- 只是演示使用方法，用于组件或者路由切换时生效 -->
    <keep-alive v-if="$route.meta.keepAlive">
      <router-view />
    </keep-alive>
    <router-view v-else />
</template>

<script>
import { defineComponent, provide } from 'vue'

export default defineComponent({
  setup () {
    const switchMode = () => {
      const mode = document.body.getAttribute('mode')
      if (mode === 'dark') {
        document.body.removeAttribute('mode', 'dark')
        localStorage.removeItem('mode')
      } else {
        document.body.setAttribute('mode', 'dark')
        localStorage.setItem('mode', 'dark')
      }
    }
    provide('switchMode', switchMode)
  }
})
</script>

<style lang="less">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

nav {
  padding: 30px;

  a {
    font-weight: bold;
    color: #2c3e50;
    &.router-link-exact-active {
      color: #42b983;
      font-size: 14px;
    }
  }
}
</style>
